/**
 *   Copyright (c) fanguangping. All rights reserved.
 *   The use and distribution terms for this software are covered by the
 *   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
 *   which can be found in the file epl-v10.html at the root of this distribution.
 *   By using this software in any fashion, you are agreeing to be bound by
 * 	 the terms of this license.
 *   You must not remove this notice, or any other, from this software.
 **/
package org.jfunny.core.ds;

import java.util.ArrayList;
import java.util.List;

/**
 * 参数节点，表示 { 与 } 括起来的部分，是树干
 * 
 * @author fanguangping
 *
 */
public class Arg implements Statement {
	private ArrayList<Statement> statements = new ArrayList<Statement>();

	public boolean addChild(Statement statement) {
		return statements.add(statement);
	}

	public boolean removeChild(Statement statement) {
		return statements.remove(statement);
	}

	public List<Statement> getChildren() {
		return statements;
	}

	public void setChildren(ArrayList<Statement> statements) {
		this.statements = statements;
	}

	public String getContent() {
		String str = "";

		Statement last = null;
		for (Statement s : statements) {
			if (last != null && last instanceof Symbol && s instanceof Symbol) {
				str += " ";
			}
			str += s;
			last = s;
		}

		return str;
	}

	public String toString() {
		String str = "{";

		Statement last = null;
		for (Statement s : statements) {
			if (last != null && last instanceof Symbol && s instanceof Symbol) {
				str += " ";
			}
			str += s;
			last = s;
		}
		str += "}";

		return str;
	}
}
